package com.marvels.approve.task.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.approve.task.dto.TimedTaskMonitoreDTO;
import com.marvels.approve.task.service.ApproveTimedTaskMonitoreApi;

@RequestMapping("approve/timedTask/service")
@RestController
public class ApproveTimedTaskMonitoredcontroller {
	
	@Autowired
	private ApproveTimedTaskMonitoreApi timedTaskMonitoreApi;
	
	/**
	 * 查询定时任务信息
	 * @param monitoreDTO
	 * @return
	 */
	@RequestMapping("selectTaskList")
	@ResponseBody
	public MarvelsResultDTO selectTaskList(@RequestBody TimedTaskMonitoreDTO monitoreDTO){
		try {
			Page<TimedTaskMonitoreDTO> list=timedTaskMonitoreApi.selectTaskList(monitoreDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),
					list);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>查询定时任务信息异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					null);
		}
		
	}
	
	
	
	/**
	 * 查询定时任务信息
	 * @param monitoreDTO
	 * @return
	 */
	@RequestMapping("runTimedTaskAgain")
	@ResponseBody
	public MarvelsResultDTO runTimedTaskAgain(@RequestBody TimedTaskMonitoreDTO monitoreDTO){
		try {
			timedTaskMonitoreApi.runTimedTaskAgain(monitoreDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),
					null);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>定时任务name:"+monitoreDTO.getJobName()+",执行异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					null);
		}
		
	}
	
}
